<?php

namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\Db;

class CommentController extends AdminBaseController
{
    /*评价管理*/
    public function index()
    {
        $commentData = model('MarketComment')->getComment();
        $datas = $commentData->toArray()['data'];
        foreach ($datas as &$data) {
            if (!empty($data['img'])) {
                $data['img'] = explode('|', $data['img']);
            }
            $data['time'] = date('Y-m-d H:i:s', $data['time']);
        }
        return view('', compact('datas', 'commentData'));
    }

    //查看评论
    public function see()
    {
        $id = input('id', 0, 'intval');
        if ($id == 0) {
            $this->error('参数没找到');
        }
        $datas = db('market_comment')->find($id);
        if (!empty($datas ['img'])) {
            $datas ['img'] = explode('|', $datas ['img']);
        }
        return view('', compact('datas'));
    }

    //删除评论
    public function del()
    {
        $id = input('id', 0, 'intval');
        if ($id == 0) {
            $this->error('参数没找到');
        }
        $res = Db::name('market_comment')->delete($id);
        if ($res) {
            $this->success('删除成功');
        } else {
            $this->error('删除失败');
        }
    }

    //批量删除评论
    public function delMore()
    {
        if (!isPost()) {
            $this->error('请求方式错误');
        }
        $param = input('commentid', '');
        if (empty($param)) {
            $this->error('传入参数错误');
        }
        if (Db::name('market_comment')->delete($param)) {
            $this->success('删除成功');
        } else {
            $this->error('删除失败');
        };
    }
}
